var fs = require('fs');

// 读取流
// var data = '';
// var readStream = fs.createReadStream("test.js");
// // console.log(readStream);
// readStream.setEncoding('utf8');
// readStream.on('data',function(_d){
//   data += _d;
// });
// readStream.on('end',function(_d){
//   console.log(data);
// });

// 写入流
// var fileUtil = require("./lib/fileUtil");
// var data = '我是顶顶顶顶.';
// fileUtil.mkdirsSync('./tmp');
// var writeStream = fs.createWriteStream('./tmp/write.txt');
// writeStream.write(data,'utf8');
// writeStream.end();
// writeStream.on('finish',function(){
//   console.log("写入完成");
// });

// 管道流
// var readStream = fs.createReadStream("test.js");
// var writeStream = fs.createWriteStream('./tmp/test.js.bak');
// readStream.pipe(writeStream);

// 链式流,一般用来操作管道流
var zlib = require('zlib');
// fs.createReadStream("test.js")
  // .pipe(zlib.createGzip())
  // .pipe(fs.createWriteStream('./tmp/test.js.gz'));
// console.log('压缩完了');
fs.createReadStream("./tmp/test.js.gz")
  .pipe(zlib.createGunzip())
  .pipe(fs.createWriteStream('./tmp/test.js.unzip'));
console.log('解压完了');
